//
//  BMALrc.m
//  LZMusicPlayer
//
//  Created by wulanzhou on 2016/11/10.
//  Copyright © 2016年 wulanzhou. All rights reserved.
//

#import "BMALrc.h"
#import "BMABase.h"
#import <AFNetworking/AFNetworking.h>

@implementation BMALrc

- (void)lrcURLString:(NSString *)urlString completion:(void (^) (NSArray <LrcDecode *> *lrcArray)) completion{

    
    //NSURL *URL = [NSURL URLWithString:urlString];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    //manager.responseSerializer.acceptableContentTypes = [[NSSet alloc] initWithObjects:@"application/xml", @"text/xml",@"application/lrc", nil];
    [manager GET:urlString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSString *lrcString = nil;
        if ([responseObject isKindOfClass:[NSData class]]) {
            lrcString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        }
        //DLog(@"lrcString: %@", lrcString);
        NSArray *arr = [LrcDecode convertLrcStringToOjbect:lrcString];
        if (completion) {
            completion(arr);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        DLog(@"Error: %@", error);
        if (completion) {
            completion(nil);
        }
    }];
}

@end
